using System.Collections;
using UnityEngine;

public class BackgroundAutoScale : MonoBehaviour
{
	public static BackgroundAutoScale instance;

	public bool noneX;

	public bool noneY;

	private Vector3 xWidth;

	private Vector3 yHeight;

	private void Start()
	{
		StartCoroutine(delay());
	}

	public void autoScale()
	{
		SpriteRenderer component = GetComponent<SpriteRenderer>();
		if (!(component == null))
		{
			base.transform.localScale = new Vector3(1f, 1f, 1f);
			float x = component.sprite.bounds.size.x;
			float y = component.sprite.bounds.size.y;
			float num = Camera.main.orthographicSize * 2f;
			float num2 = num / (float)Screen.height * (float)Screen.width;
			if (!noneX)
			{
				xWidth = base.transform.localScale;
				xWidth.x = num2 / x;
				base.transform.localScale = xWidth;
			}
			if (!noneY)
			{
				yHeight = base.transform.localScale;
				yHeight.y = num / y;
				base.transform.localScale = yHeight;
			}
		}
	}

	private IEnumerator delay()
	{
		yield return new WaitForSecondsRealtime(0.05f);
		autoScale();
	}
}
